window.onload = function(){
    var items = document.getElementsByName("items");
   
 var chooseAll = document.getElementById("chooseAll");
 var chooseNone = document.getElementById("chooseNone");
 var inverse = document.getElementById("inverse");
 var submit = document.getElementById("submit");
 var button = document.getElementById("button");

     chooseAll.onclick = function(){
         
     for(var i=0;i<items.length;i++){
        items[i].checked = true;
     }
        button.checked = true;
     };

     chooseNone.onclick = function(){
         for(var i=0;i<items.length;i++){
             items[i].checked = false;
         }
         button.checked = false;
     };

    inverse.onclick = function(){
        button.checked = true;
        for(var i=0;i<items.length;i++){
            items[i].checked = !items[i].checked;
            if(!items[i].checked){
                button.checked = false;
            }
        }
    }   

    submit.onclick = function(){
        for(var i=0;i<items.length;i++){
          if(items[i].checked){
              console.log(items[i].value);
          }
        }
    
    }

    //在事件的响应函数中，响应函数是给谁绑定的，this就是谁
    button.onclick = function(){
        for(var i=0;i<items.length;i++){
            items[i].checked = this.checked;
        }
    };

    
    //为四个多选框分别绑定点击函数
    for(var i=0;i<items.length;i++){
        items[i].onclick = function(){
            button.checked = true;
            for(var j=0;j<items.length;j++){
                if(!items[j].checked){
                    button.checked = false;
                    break;
                }
              
            }
            
        }
    }



 }


